< previous page page_730 next page >

Page 730
Understanding the Key Events of a UserDocument
Although the UserDocument is similar to a form in many respects, it also has some key differences. For example, several key properties, methods, and events are supported by a UserDocument but are not supported by a form, and vice versa. The reason for these differences is the different nature of the objects themselves: A form is independent, whereas a UserDocument is always in a container.
The main events of a form that are not supported by the UserDocument object are the Activate, Deactivate, Load, and Unload events. The UserDocument, on the other hand, supports the following events that are not supported by a form:
AsycReadComplete. Occurs when the container holding the document has finished an asynchronous read request.
EnterFocus. Occurs when the ActiveX document receives focus.
ExitFocus. Occurs when the ActiveX document loses focus.
Hide. Occurs when the user navigates from the current ActiveX document to another document.
InitProperties. Occurs when the document is first loaded. However, if any properties have been saved using the PropertyBag object, the ReadProperties event occurs instead.
ReadProperties. Occurs in place of the InitProperties event if items are stored in a PropertyBag object. This event also occurs as the document is first loaded.
Scroll. Occurs when the user uses the scrollbar of the container in which the ActiveX document is running.
Show. Occurs when the user navigates from another document to the ActiveX document.
WriteProperties. Occurs as the program is about to be terminated. This event happens right before the Terminate event, but it occurs only if the PropertyChanged statement has been used to indicate that a change has occurred in a property's value.
Creating and Storing Properties for a UserDocument
Despite the similarities between the UserDocument and a form, in some ways the UserDocument is much more similar to a UserControl than a form. All three objectsthe form, the UserControl, and the UserDocumentenable you to create properties and methods to extend their capabilities. However, only the UserControl and the UserDocument have the capability to use the PropertyBag object. The PropertyBag object, along with some special events, is used to store values of public properties so that settings are preserved between sessions.
Because the process for creating and saving properties was discussed in detail in the coverage of ActiveX controls, I won't repeat the details here (see Chapter 14, "Creating ActiveX Controls"). However, a quick recap may help you remember the steps involved. To create and store properties for the UserDocument, you need to do the following:

 
< previous page page_730 next page >